package com.ggb.reactive.repository

import com.ggb.reactive.domain.entity.SetmealDish
import com.ggb.reactive.domain.vo.DishItemVO
import org.springframework.data.r2dbc.repository.Modifying
import org.springframework.data.r2dbc.repository.Query
import org.springframework.data.repository.reactive.ReactiveCrudRepository
import org.springframework.stereotype.Repository
import reactor.core.publisher.Flux
import reactor.core.publisher.Mono

@Repository
interface SetmealDishRepository: ReactiveCrudRepository<SetmealDish,Long> {
    fun deleteBySetmealId(id: Long): Mono<Long>
    fun findSetmealDishBySetmealId(id: Long): Flux<SetmealDish>
    fun deleteBySetmealIdIn(ids: List<Long>): Mono<Long>

    @Modifying
    @Query("SELECT sd.name, sd.copies, d.image, d.description FROM setmeal_dish sd LEFT JOIN dish d ON sd.dish_id = d.id WHERE sd.setmeal_id = :setmealId")
    fun getDishItemBySetmealId(setmealId: Long): Flux<DishItemVO>
    fun findByDishIdIn(ids: List<Long>): Mono<SetmealDish>
    fun countAllByDishIdIn(dishIds: List<Long>): Mono<Int>


}